Telegram Group & Telegram Channel
Строковый метод translate позволяет заменять или удалять несколько символов в строке за один раз. Это похоже на множественные вызовы метода replace.

```python
import string

s = "Hello, world!"
print(s.translate(str.maketrans("", "", string.punctuation)))
# Hello world
```

Метод translate ожидает «таблицу перевода», которую мы создаем с помощью вспомогательного метода класса maketrans.

Третий аргумент (string.punctuation в примере) — это строка символов, которые мы хотим удалить.

Значение string.punctuation включает в себя следующие символы:
!#$%&'()*+,-./:;?@[\]^_{|}~`

Суть шпаргалки заключается в том, что она демонстрирует, как эффективно удалить все стандартные знаки препинания из строки в Python, используя комбинацию методов str.maketrans для создания инструкции по удалению и str.translate для применения этой инструкции к строке.

@Python_Community_ru



tg-me.com/Python_Community_ru/2559
Create:
Last Update:

Строковый метод translate позволяет заменять или удалять несколько символов в строке за один раз. Это похоже на множественные вызовы метода replace.

```python
import string

s = "Hello, world!"
print(s.translate(str.maketrans("", "", string.punctuation)))
# Hello world
```

Метод translate ожидает «таблицу перевода», которую мы создаем с помощью вспомогательного метода класса maketrans.

Третий аргумент (string.punctuation в примере) — это строка символов, которые мы хотим удалить.

Значение string.punctuation включает в себя следующие символы:
!#$%&'()*+,-./:;?@[\]^_{|}~`

Суть шпаргалки заключается в том, что она демонстрирует, как эффективно удалить все стандартные знаки препинания из строки в Python, используя комбинацию методов str.maketrans для создания инструкции по удалению и str.translate для применения этой инструкции к строке.

@Python_Community_ru

BY Python Community




Share with your friend now:
tg-me.com/Python_Community_ru/2559

View MORE
Open in Telegram


Python Community Telegram | DID YOU KNOW?

Date: |

What is Secret Chats of Telegram

Secret Chats are one of the service’s additional security features; it allows messages to be sent with client-to-client encryption. This setup means that, unlike regular messages, these secret messages can only be accessed from the device’s that initiated and accepted the chat. Additionally, Telegram notes that secret chats leave no trace on the company’s services and offer a self-destruct timer.

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

Python Community from pl


Telegram Python Community
FROM USA